app.controller("specificationController",function(
    $scope,
    $controller,
    specificationService){
    $scope.list = [];//页面显示的列表
    $scope.searchEntity = {};//搜索用的数据
    $scope.entity = {spec:{},specOptionList:[]};//编辑保存用的实体数据
    $controller("baseController",{$scope:$scope});
    $scope.search = function(page,rows){
        specificationService.findPage(page,rows,$scope.searchEntity).then(function(result){
            $scope.list = result.data.rows;
            $scope.pageModel.totalItems = result.data.total;
        });
    }
    //添加一行
    $scope.addOption = function(){
        $scope.entity.specOptionList.push({});
    }
    $scope.delOption = function($index){
        $scope.entity.specOptionList.splice($index,1);
    }
    $scope.save = function(){
        if($scope.entity.spec.id){
            specificationService.update($scope.entity).then(function(result){
                if(result.data.success){
                    //刷新列表
                    $scope.reloadList();
                }else {
                    alert(result.data.message);
                }
            });
        }else{
            specificationService.save($scope.entity).then(function(result){
                if(result.data.success){
                    //刷新列表
                    $scope.reloadList();
                }else {
                    alert(result.data.message);
                }
            });
        }
    }
    $scope.edit = function(id){
        specificationService.findOne(id).then(function(result){
            $scope.entity = result.data;
        });
    }
    $scope.dele = function(){
        specificationService.dele($scope.selectedIds).then(function(result){
            if(result.data.success){
                //刷新列表
                $scope.reloadList();
            }else {
                alert(result.data.message);
            }
        });
    }
});